package com.konne.nightmare.FastPublicOpinion.ui.information.adapter;

import android.view.View;
import android.widget.ImageView;

import com.blankj.utilcode.util.SizeUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.coorchice.library.SuperTextView;
import com.konne.nightmare.FastPublicOpinion.R;
import com.konne.nightmare.FastPublicOpinion.bean.MembersBean;
import com.shehuan.niv.NiceImageView;

import java.util.List;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * Create by ws.
 * on Data:2022/1/24  Time:下午 4:49.
 * description: 成员管理 全部成员适配器 .
 */
public class MembersManagerMAdapter extends BaseMultiItemQuickAdapter<MembersBean, BaseViewHolder> {
    private MembersManagerListener membersManagerListener;

    public void setMembersManagerListener(MembersManagerListener membersManagerListener) {
        this.membersManagerListener = membersManagerListener;
    }

    public MembersManagerMAdapter(List<MembersBean> data) {
        super(data);
        addItemType(MenberType.StudentGroup.type, R.layout.item_menbers_group);
        addItemType(MenberType.TeacherGroup.type, R.layout.item_menbers_group);
        addItemType(MenberType.Teacher.type, R.layout.item_menbers_user);
        addItemType(MenberType.Student.type, R.layout.item_menbers_user);

    }
    @Override
    protected void convert(BaseViewHolder helper, MembersBean item) {

        if (item.getItemType() == MenberType.TeacherGroup.type) {
            helper.setVisible(R.id.tv_sub_title, true)
                    .setText(R.id.tv_title, "授课教学团队")
                    .setVisible(R.id.view_gap, false)
                    .setOnClickListener(R.id.tv_sub_title, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if(membersManagerListener!=null){
                                membersManagerListener.action(5);
                            }
                        }
                    });
            SuperTextView iv_arrow=helper.getView(R.id.iv_arrow);
            if(item.isOpen()){
                iv_arrow.setDrawableRotate(90);
            }else {
                iv_arrow.setDrawableRotate(-90);
            }
            helper.getView(R.id.ll_content).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(membersManagerListener!=null){
                        membersManagerListener.action(item.isOpen()?1:2);
                    }
                }
            });
        } else if (item.getItemType() == MenberType.StudentGroup.type) {
            helper.setVisible(R.id.tv_sub_title, false)
                    .setText(R.id.tv_title, "全部学生")
                    .setVisible(R.id.view_gap, true);
            SuperTextView iv_arrow=helper.getView(R.id.iv_arrow);
            if(item.isOpen()){
                iv_arrow.setDrawableRotate(90);
            }else {
                iv_arrow.setDrawableRotate(-90);
            }
            helper.getView(R.id.ll_content).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(membersManagerListener!=null){
                        membersManagerListener.action(item.isOpen()?3:4);
                    }
                }
            });
        } else {
            helper.setText(R.id.tv_name, item.getName())
                    .setVisible(R.id.stv_tag, item.getItemType() == MenberType.Teacher.type)
                    .setVisible(R.id.stv_chat, item.getItemType() == MenberType.Student.type);
            NiceImageView avatar = helper.getView(R.id.ic_avatar);
            Glide.with(avatar).load(item.getAvatar()).apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(SizeUtils.dp2px(20),0))).into(avatar);
            if (item.getItemType() == MenberType.Teacher.type) {
                SuperTextView stv_tag = helper.getView(R.id.stv_tag);
                stv_tag.setText(item.getRole());
                stv_tag.setSolid(item.getRole().equals("助教")?0xff9ECDFF:0xff3396FE);
            } else {

            }
        }
    }
    public enum MenberType {
        Teacher(1), Student(0), TeacherGroup(2), StudentGroup(3);
        public int type;

        MenberType(int type) {
            this.type = type;
        }
    }
    public interface MembersManagerListener{
        void action(int action);
    }
}
